let id = 0
function loop() {
  let img = document.querySelector('.box>.img')
  if (id) {
    clearInterval(id)
  }
  let index = 1
  id = setInterval(function () {
    index++
    let src = `./img/${index}.png`
    console.log(src)
    img.src = src
    if (index === 6) {
      index = 0
    }
  }, 3000)
}

loop()
